﻿using System.Windows.Forms;
using System;

namespace Slippor.Douban.Radio.Assist
{
    public class MessageFilter : IMessageFilter
    {
        public FilterClick FilterClick;
        private IntPtr _handler;
        public IntPtr Handler
        {
            get { return _handler; }
            set { _handler = value; }
        }

        public MessageFilter(IntPtr handler)
        {
            _handler = handler;
        }

        #region IMessageFilter Members

        public bool PreFilterMessage(ref Message m)
        {
            if (m.Msg == 0x0202 && m.HWnd == _handler)
            {
                var x = (int) ((uint) m.LParam & 0xFFFF);
                var y = (int) ((uint) m.LParam >> 16);
                if (FilterClick != null)
                {
                    return FilterClick(x, y);
                }
                else
                {
                    return false;
                }
            }
            return false;
        }

        #endregion
    }

    public delegate bool FilterClick(int x, int y);
}